<!DOCTYPE html>
<html>
<head>
<title>SpringCloud.md</title>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">

<style>
/* https://github.com/microsoft/vscode/blob/master/extensions/markdown-language-features/media/markdown.css */
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

body {
	font-family: var(--vscode-markdown-font-family, -apple-system, BlinkMacSystemFont, "Segoe WPC", "Segoe UI", "Ubuntu", "Droid Sans", sans-serif);
	font-size: var(--vscode-markdown-font-size, 14px);
	padding: 0 26px;
	line-height: var(--vscode-markdown-line-height, 22px);
	word-wrap: break-word;
}

#code-csp-warning {
	position: fixed;
	top: 0;
	right: 0;
	color: white;
	margin: 16px;
	text-align: center;
	font-size: 12px;
	font-family: sans-serif;
	background-color:#444444;
	cursor: pointer;
	padding: 6px;
	box-shadow: 1px 1px 1px rgba(0,0,0,.25);
}

#code-csp-warning:hover {
	text-decoration: none;
	background-color:#007acc;
	box-shadow: 2px 2px 2px rgba(0,0,0,.25);
}

body.scrollBeyondLastLine {
	margin-bottom: calc(100vh - 22px);
}

body.showEditorSelection .code-line {
	position: relative;
}

body.showEditorSelection .code-active-line:before,
body.showEditorSelection .code-line:hover:before {
	content: "";
	display: block;
	position: absolute;
	top: 0;
	left: -12px;
	height: 100%;
}

body.showEditorSelection li.code-active-line:before,
body.showEditorSelection li.code-line:hover:before {
	left: -30px;
}

.vscode-light.showEditorSelection .code-active-line:before {
	border-left: 3px solid rgba(0, 0, 0, 0.15);
}

.vscode-light.showEditorSelection .code-line:hover:before {
	border-left: 3px solid rgba(0, 0, 0, 0.40);
}

.vscode-light.showEditorSelection .code-line .code-line:hover:before {
	border-left: none;
}

.vscode-dark.showEditorSelection .code-active-line:before {
	border-left: 3px solid rgba(255, 255, 255, 0.4);
}

.vscode-dark.showEditorSelection .code-line:hover:before {
	border-left: 3px solid rgba(255, 255, 255, 0.60);
}

.vscode-dark.showEditorSelection .code-line .code-line:hover:before {
	border-left: none;
}

.vscode-high-contrast.showEditorSelection .code-active-line:before {
	border-left: 3px solid rgba(255, 160, 0, 0.7);
}

.vscode-high-contrast.showEditorSelection .code-line:hover:before {
	border-left: 3px solid rgba(255, 160, 0, 1);
}

.vscode-high-contrast.showEditorSelection .code-line .code-line:hover:before {
	border-left: none;
}

img {
	max-width: 100%;
	max-height: 100%;
}

a {
	text-decoration: none;
}

a:hover {
	text-decoration: underline;
}

a:focus,
input:focus,
select:focus,
textarea:focus {
	outline: 1px solid -webkit-focus-ring-color;
	outline-offset: -1px;
}

hr {
	border: 0;
	height: 2px;
	border-bottom: 2px solid;
}

h1 {
	padding-bottom: 0.3em;
	line-height: 1.2;
	border-bottom-width: 1px;
	border-bottom-style: solid;
}

h1, h2, h3 {
	font-weight: normal;
}

table {
	border-collapse: collapse;
}

table > thead > tr > th {
	text-align: left;
	border-bottom: 1px solid;
}

table > thead > tr > th,
table > thead > tr > td,
table > tbody > tr > th,
table > tbody > tr > td {
	padding: 5px 10px;
}

table > tbody > tr + tr > td {
	border-top: 1px solid;
}

blockquote {
	margin: 0 7px 0 5px;
	padding: 0 16px 0 10px;
	border-left-width: 5px;
	border-left-style: solid;
}

code {
	font-family: Menlo, Monaco, Consolas, "Droid Sans Mono", "Courier New", monospace, "Droid Sans Fallback";
	font-size: 1em;
	line-height: 1.357em;
}

body.wordWrap pre {
	white-space: pre-wrap;
}

pre:not(.hljs),
pre.hljs code > div {
	padding: 16px;
	border-radius: 3px;
	overflow: auto;
}

pre code {
	color: var(--vscode-editor-foreground);
	tab-size: 4;
}

/** Theming */

.vscode-light pre {
	background-color: rgba(220, 220, 220, 0.4);
}

.vscode-dark pre {
	background-color: rgba(10, 10, 10, 0.4);
}

.vscode-high-contrast pre {
	background-color: rgb(0, 0, 0);
}

.vscode-high-contrast h1 {
	border-color: rgb(0, 0, 0);
}

.vscode-light table > thead > tr > th {
	border-color: rgba(0, 0, 0, 0.69);
}

.vscode-dark table > thead > tr > th {
	border-color: rgba(255, 255, 255, 0.69);
}

.vscode-light h1,
.vscode-light hr,
.vscode-light table > tbody > tr + tr > td {
	border-color: rgba(0, 0, 0, 0.18);
}

.vscode-dark h1,
.vscode-dark hr,
.vscode-dark table > tbody > tr + tr > td {
	border-color: rgba(255, 255, 255, 0.18);
}

</style>

<style>
/* Tomorrow Theme */
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
/* Original theme - https://github.com/chriskempson/tomorrow-theme */

/* Tomorrow Comment */
.hljs-comment,
.hljs-quote {
	color: #8e908c;
}

/* Tomorrow Red */
.hljs-variable,
.hljs-template-variable,
.hljs-tag,
.hljs-name,
.hljs-selector-id,
.hljs-selector-class,
.hljs-regexp,
.hljs-deletion {
	color: #c82829;
}

/* Tomorrow Orange */
.hljs-number,
.hljs-built_in,
.hljs-builtin-name,
.hljs-literal,
.hljs-type,
.hljs-params,
.hljs-meta,
.hljs-link {
	color: #f5871f;
}

/* Tomorrow Yellow */
.hljs-attribute {
	color: #eab700;
}

/* Tomorrow Green */
.hljs-string,
.hljs-symbol,
.hljs-bullet,
.hljs-addition {
	color: #718c00;
}

/* Tomorrow Blue */
.hljs-title,
.hljs-section {
	color: #4271ae;
}

/* Tomorrow Purple */
.hljs-keyword,
.hljs-selector-tag {
	color: #8959a8;
}

.hljs {
	display: block;
	overflow-x: auto;
	color: #4d4d4c;
	padding: 0.5em;
}

.hljs-emphasis {
	font-style: italic;
}

.hljs-strong {
	font-weight: bold;
}
</style>

<style>
/*
 * Markdown PDF CSS
 */

 body {
	font-family: -apple-system, BlinkMacSystemFont, "Segoe WPC", "Segoe UI", "Ubuntu", "Droid Sans", sans-serif, "Meiryo";
	padding: 0 12px;
}

pre {
	background-color: #f8f8f8;
	border: 1px solid #cccccc;
	border-radius: 3px;
	overflow-x: auto;
	white-space: pre-wrap;
	overflow-wrap: break-word;
}

pre:not(.hljs) {
	padding: 23px;
	line-height: 19px;
}

blockquote {
	background: rgba(127, 127, 127, 0.1);
	border-color: rgba(0, 122, 204, 0.5);
}

.emoji {
	height: 1.4em;
}

code {
	font-size: 14px;
	line-height: 19px;
}

/* for inline code */
:not(pre):not(.hljs) > code {
	color: #C9AE75; /* Change the old color so it seems less like an error */
	font-size: inherit;
}

/* Page Break : use <div class="page"/> to insert page break
-------------------------------------------------------- */
.page {
	page-break-after: always;
}

</style>

<script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
</head>
<body>
  <script>
    mermaid.initialize({
      startOnLoad: true,
      theme: document.body.classList.contains('vscode-dark') || document.body.classList.contains('vscode-high-contrast')
          ? 'dark'
          : 'default'
    });
  </script>
<h1 id="%E7%AE%80%E4%BB%8B">简介</h1>
<p>笔记来源：<a href="https://www.itmuch.com/spring-cloud/finchley-1/">教程文档</a></p>
<h2 id="%E6%A6%82%E5%BF%B5">概念</h2>
<p><strong>SpringBoot基础上构建， 勇于快速构建分布式系统的通用模式的工具集</strong></p>
<h2 id="%E6%A0%B8%E5%BF%83%E5%8A%9F%E8%83%BD">核心功能</h2>
<ul>
<li>Distributed/versioned configuration 分布式/版本化的配置管理</li>
<li>Service registration and discovery 服务注册与服务发现</li>
<li>Routing 路由</li>
<li>Service-to-service calls 端到端的调用</li>
<li>Load balancing 负载均衡</li>
<li>Circuit Breakers 断路器</li>
<li>Global locks 全局锁</li>
<li>Leadership election and cluster state 选举与集群状态管理</li>
<li>Distributed messaging 分布式消息</li>
</ul>
<h2 id="%E7%89%88%E6%9C%AC%E7%AE%80%E4%BB%8B">版本简介</h2>
<h2 id="%E7%89%88%E6%9C%AC%E4%BB%A5%E5%8F%8A%E5%85%BC%E5%AE%B9%E6%80%A7">版本以及兼容性</h2>
<p><a href="https://github.com/spring-cloud/spring-cloud-release/wiki">版本总览</a>
<img src="file:///c:/Users/mengxue.wu/Desktop/Mystudy/Mynote/SpringCloud/img/version.jpg" alt="版本图片">
springCloud包含许多子服务。为避免和其他项目混淆，改用SRX命名。大版本修改命名为伦敦地铁站名。SR指bug修复版本</p>
<h2 id="%E9%A1%B9%E7%9B%AE%E7%BD%91%E7%AB%99%E5%92%8C%E6%BC%94%E8%BF%9B">项目网站和演进</h2>
<ul>
<li>版本发布：(https://github.com/spring-cloud/spring-cloud-release/releases)</li>
<li>版本演进:(https://github.com/spring-cloud/spring-cloud-release/milestones)</li>
</ul>
<h2 id="%E5%AD%90%E9%A1%B9%E7%9B%AE%E7%89%88%E6%9C%AC">子项目版本</h2>
<p><img src="file:///c:/Users/mengxue.wu/Desktop/Mystudy/Mynote/SpringCloud/img/version.jpg" alt=""></p>
<h1 id="spring-bootspring-cloud%E5%BA%94%E7%94%A8%E4%B8%89%E6%9D%BF%E6%96%A7">Spring Boot/Spring Cloud应用三板斧</h1>
<ul>
<li>加依赖</li>
<li>加注解</li>
<li>些配置</li>
</ul>
<p><a href="%5Bhttps://projectlombok.org/%5D(https://projectlombok.org/)">Lombok官方网站</a></p>
<p><a href="%5Bhttps://blog.csdn.net/motui/article/details/79012846%5D(https://blog.csdn.net/motui/article/details/79012846)">Lombok快速上手</a></p>
<h1 id="%E7%9B%91%E6%8E%A7spring-boot-actuator">监控:Spring Boot Actuator</h1>
<h2 id="%E4%BD%BF%E7%94%A8">使用</h2>
<pre class="hljs"><code><div><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>  
  <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>  
  <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-actuator<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>  
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</div></code></pre>
<h2 id="%E7%9B%91%E6%8E%A7%E7%AB%AF%E7%82%B9">监控端点</h2>
<p><a href="https://docs.spring.io/spring-boot/docs/current/actuator-api/htmlsingle/#overview.endpoint-urls">Spring Boot Actuator Web API Documentation</a>)</p>
<h3 id="%E7%AB%AF%E7%82%B9%E9%85%8D%E7%BD%AE">端点配置</h3>
<pre class="hljs"><code><div><span class="hljs-comment"># 配置actuator  </span>
<span class="hljs-attr">management:</span>  
 <span class="hljs-attr">endpoint:</span>  
   <span class="hljs-comment">#配置health端口  </span>
   <span class="hljs-attr">health:</span>  
     <span class="hljs-attr">show-details:</span> <span class="hljs-string">always</span>  
 <span class="hljs-attr">endpoints:</span>  
   <span class="hljs-attr">web:</span>  
     <span class="hljs-attr">exposure:</span>  
       <span class="hljs-comment">#映射全部接口  </span>
       <span class="hljs-attr">include:</span> <span class="hljs-string">"*"</span>
</div></code></pre>
<h1 id="%E6%9C%8D%E5%8A%A1%E6%B3%A8%E5%86%8C%E5%92%8C%E6%9C%8D%E5%8A%A1%E5%8F%91%E7%8E%B0">服务注册和服务发现</h1>
<h2 id="%E6%9C%8D%E5%8A%A1%E5%8F%91%E7%8E%B0%E5%8E%9F%E7%90%86">服务发现原理</h2>
<p><img src="file:///c:/Users/mengxue.wu/Desktop/Mystudy/Mynote/SpringCloud/img/registry.jpg" alt=""></p>
<p>服务提供者、服务消费者、服务发现组件这三者之间的关系大致如下：</p>
<ul>
<li>
<p>各个<strong>微服务在启动时，将自己的网络地址等信息注册到服务发现组件中</strong>，服务发现组件会存储这些信息；</p>
</li>
<li>
<p><strong>服务消费者可从服务发现组件查询服务提供者的网络地址</strong>，并使用该地址调用服务提供者的接口；</p>
</li>
<li>
<p>各个微服务与服务发现组件<strong>使用一定机制（例如心跳）通信</strong>。服务发现组件如长时间无法与某微服务实例通信，就会自动注销（即：删除）该实例；</p>
</li>
<li>
<p>当微服务网络地址发生变更（例如实例增减或者IP端口发生变化等）时，会<strong>重新注册</strong>到服务发现组件；</p>
</li>
<li>
<p><strong>客户端缓存</strong>：各个微服务将需要调用服务的地址缓存在本地，并使用一定机制更新（例如定时任务更新、事件推送更新等）。这样既能降低服务发现组件的压力，同时，即使服务发现组件出问题，也不会影响到服务之间的调用。</p>
</li>
</ul>
<p>综上，服务发现组件应具备以下功能。</p>
<ul>
<li>
<p><strong>服务注册表（核心）</strong>：服务注册表是服务发现组件的核心（其实就是类似于上面的registry表），它用来记录各个微服务的信息，例如微服务的名称、IP、端口等。服务注册表提供查询API和管理API，查询API用于查询可用的微服务实例，管理API用于服务的注册和注销；</p>
</li>
<li>
<p><strong>服务注册与服务发现</strong>：服务注册是指微服务在启动时，将自己的信息注册到服务发现组件上的过程。服务发现是指查询可用微服务列表及其网络地址的机制；</p>
</li>
<li>
<p><strong>服务检查</strong>：服务发现组件使用一定机制定时检测已注册的服务，如发现某实例长时间无法访问，就会从服务注册表中移除该实例。</p>
</li>
</ul>
<p>综上，使用服务发现的好处是显而易见的。Spring Cloud为我们提供多种服务发现组件的支持，例如Eureka、Consul（spring-cloud-consul）、Zookeeper（spring-cloud-zookeeper）、Aliaba Nacos（孵化中：spring-cloud-alibaba）、Etcd（孵化中：spring-cloud-etcd）等。</p>
<h2 id="eureka%E7%AE%80%E4%BB%8B">EureKa简介</h2>
<p>Netflix开源服务发现组件 基于REST。
<a href="%5Bhttps://github.com/Netflix/Eureka%5D(https://github.com/Netflix/Eureka)">GitHub网址</a></p>

</body>
</html>
